const api = require('../../../api/index.js');
let app = getApp();
Page({
  data:{
    array: ['女', '男'],
    MyChron: ['放松心情', '追求刺激', '兴趣体验','提升气质'],
    Interest: ['高尔夫', '高尔夫', '马术', '击剑', '冰雪', '卡丁车', '射箭', '冲浪', '潜水', '攀岩','保龄球'],
    rank: ['运动小白求人带', '偶尔运动无障碍','运动达人上手快'],
    receptivity: ['容易 (慢走)', '中等 (健步走)', '中等偏难 (3公里慢跑）', '难 (5～10公里慢跑）','困难 (有对抗）'],
    participation: ['足球', '篮球', '跑步', '健身', '游泳', '瑜伽', '跑步','没有或不参加'],
    expenditure: ['100元以下', '100～200元', '200～300元','300元以上'],
    social: ['企业主', '个体商户', '移动互联网', '电子商务', '房地产', '媒体营销', '智能硬件', '企业服务', '容医疗健康', '文体娱乐', '金融保险','进出口贸易'],
    meListData: [], // 当前数据
    selectData: [],
    userData: {}
  },
  onLoad: function(options){
   
  },
  onShow:function(){
    this.getData();// 获取选择数据
    this.submitMeData({}); // 提交数据
    App.zhuge.track('完善运动档案-页面', {})
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //性别   
    let sex = e.detail.value;
    if(sex == 0){
      sex = 1;
    }else{
      sex = 2
    }

    this.submitMe({user_sex: sex})
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //生日
    this.submitMe({ user_birth: e.detail.value})
    
  },
  bindMyChronChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //运动目的
    let value = this.data.selectData.sports_goal[e.detail.value].aim_info;
    console.log(value)
     this.submitMe({ sports_goal: value})

  },
  bindInterestChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //感兴趣的运动
    let value = this.data.selectData.care_sports[e.detail.value].sports_name;
    console.log(value)
    this.submitMe({ care_sports: value })

    //this.submitMeData({ user_birth: e.detail.value })
  },
  bindrankChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //可接受运动强度
    let value = this.data.selectData.sports_power[e.detail.value].degree_name;
    console.log(value)
    this.submitMe({ sports_power: value })
  },
  bindreceptivityChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //平时参与运动项目
    let value = this.data.selectData.sports_item[e.detail.value].item_name;
    console.log(value)
    this.submitMe({ sports_item: value })
  },
  bindexpenditureChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) // 预计运动花费
    let value = this.data.selectData.sports_cost[e.detail.value].budget_part;
    console.log(value)
    this.submitMe({ sports_cost: value })
  },
  bindsocialChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value) //社交圈
    let value = this.data.selectData.user_hub[e.detail.value].social_name;
    console.log(value)
    this.submitMe({ user_hub: value })
  },
  getData: function(){ // 获取当前选择框数据
    api.meData(res => {
      console.log(res)
      this.setData({
        selectData: res.data.result
      })
    })
  },
  submitMeData: function(data){
    api.meForm(data,(res) => {
      console.log(res)
      App.zhuge.identify('用户信息', {
        '用户信息': res.data.code
      });
      this.setData({
        userData: res.data.code
      })
    })
  },
  submitMe: function (data) {
    api.meForm(data, (res) => {
      console.log(res)
      this.setData({
        userData: res.data.result[0]
      })
    })
  }
})